﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Routing;

namespace Session_Server
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        /// <summary>
        /// 网站启动
        /// </summary>
        protected void Application_Start()
        {
            /*
                * 注意，必须先启用跨域，然后，启用注册路由
                */
            GlobalConfiguration.Configuration.EnableCors();

            GlobalConfiguration.Configure(WebApiConfig.Register);
        }
        public override void Init()
        {
            this.PostAuthenticateRequest += (sender, e) =>
            {
                HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);
            };
            base.Init();
        }

        LogHelper.LogHelper _log = new LogHelper.LogHelper();
        /// <summary>
        /// Session回话启动
        /// </summary>
        protected void Session_Start()
        {
            _log.WriteLine($"*********Session启动********");
            _log.WriteLine($"当前SessionID={Session.SessionID},CodePage={Session.CodePage},Count={Session.Count}");
        }

        protected void Session_End()
        {
            _log.WriteLine("---------Session回话结束----------");
        }
    }
}
